<?php
class ProductModel extends Eloquent{
    protected $table = 'product';
    protected $appends = array(
        'extra'
    );
    protected $hidden = array('field');
    static public $stock_status = array(
        '1' => '有库存',
        '2' => '库存不足',
        '3' => '等待 2 -3 天',
        '4' => '需要预订',
    );
    public function info(){
        return $this->hasOne('\ProductInfoModel','product_id','product_id');
    }
    public function field(){
        return $this->hasMany('ProductFieldModel','product_id','product_id');
    }
    public function getExtraAttribute(){
        $data = array();
        foreach($this->field as &$v){
            $data[$v['name']] = $v['value_'.$v['type']];
        }
        return $data;
    }
}

